﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication3
{
    /// <summary>
    /// Interaction logic for COMPortSelectView.xaml
    /// </summary>
    public partial class COMPortSelectView : UserControl
    {
        MainWindow mainWindow;

        public COMPortSelectView(MainWindow mainWindow)
        {
            this.mainWindow = mainWindow;
            InitializeComponent();
        }

        public COMPortSelectView()
        {
            InitializeComponent();
        }

        private void listCOMportButton_Click(object sender, RoutedEventArgs e)
        {
            // első mérés, feltölti a Listbox-ot az elérhető COM portokkal, ha nincs csatlakoztatva semmi, hibaüzenet
            if (this.mainWindow.Controller.PortListing( this ))
            {
                this.portselectLabel.Visibility = Visibility.Visible;
                this.portselectButton.Visibility = Visibility.Visible;
            }
            else
                this.errorLabel.Visibility = Visibility.Visible;

        }

        // első mérés végrehajtásakor először még COM portot kell választani
        private void portselectButton_Click(object sender, RoutedEventArgs e)
        {
            // ha nyitva van a port, ugrik a Measure képernyőre
            if (this.mainWindow.Controller.Connect(this.portslistBox.SelectedItem.ToString()))
                mainWindow.contentControl1.Content = new MeasureView(mainWindow);
            else
            {
                this.errorLabel.Content = "Try again!";
                this.errorLabel.Visibility = Visibility.Visible;
            }

        }
    }
}
